import Vue from 'vue'
import Router from 'vue-router'
import Login from "@/views/login/Login"
import ZuoKe from "@/views/zuoke/ZuoKe"
import Set from "@/views/set/Set"

Vue.use(Router)

const router = new Router({
  
  routes: [
    {
      path: '/',
      name: '登录后台管理系统',
      component: ZuoKe,
    },
    {
      path: '/login',
      component: Login,
    },
    {
      path: '/home',
      name: 'home',
      component: resolve => require(['@/views/Home'], resolve),//懒加载,
      // redirect: {
        
      // },
      children: [
        //数据中心
        {
          path: '/aaa',        //数据分析
          name: 'aaa',
          component: resolve => require(['@/views/aaa/aa'], resolve), //懒加载
          // meta: {
          //   requireAuth: true
          // },
        },
        {
          path: '/bbb',        //数据分析
          name: 'bbb',
          component: resolve => require(['@/views/aaa/bbb'], resolve), //懒加载
          // meta: {
          //   requireAuth: true
          // },
        },
        //数据中心
        {
          path: '/core/analysis',        //数据分析
          name: 'core_analysis',
          component: resolve => require(['@/views/core/Analysis'], resolve), //懒加载
          meta: {
            requireAuth: true
          },
        },
        {
          path: '/core/articledata',      //文章数据
          name: 'core_articledata',
          component: resolve => require(['@/views/core/ArticleData'], resolve), //懒加载
          meta: {
            requireAuth: true
          },
        },
        {
          path: '/core/historical',         //历史数据
          name: 'core_historical',
          component: resolve => require(['@/views/core/Historical'], resolve), //懒加载
          meta: {
            requireAuth: true
          },
        },
        // 文章模块
        {
          path: '/article/list', //文章列表
          name: '系',
          meta: {
            requireAuth: true, //添加字段 表示进入这个路由是需要登录的
          },
          component: resolve => require(['@/views/article/ArticleList'], resolve),//懒加载,
        },
        {
          path: '/article/testarticle', //测试富文本编辑器
          name: '/article/testarticle',
          meta: {
            requireAuth: true, //添加字段 表示进入这个路由是需要登录的
          },
          component: resolve => require(['@/views/article/testarticle'], resolve),//懒加载,
        },
        {
          path: '/article/manage', //文章审核
          name: 'article_manage',
          meta: {
            requireAuth: true, //添加字段 表示进入这个路由是需要登录的
          },
          component: resolve => require(['@/views/article/ArticleManage'], resolve),//懒加载,
        },
        {
          path: '/article/roof', //文章置顶管理
          name: 'article_roof',
          meta: {
            requireAuth: true, //添加字段 表示进入这个路由是需要登录的
          },
          component: resolve => require(['@/views/article/ArticleRoof'], resolve),//懒加载,
        },
        {
          path: '/article/release', //发布文章
          name: 'article_release',
          meta: {
            requireAuth: true, //添加字段 表示进入这个路由是需要登录的
          },
          component: resolve => require(['@/views/article/children/ArticleRelease'], resolve),//懒加载,
        },

        // 线路模块
        {
          path: '/line/list', //线路列表
          name: 'line_list',
          meta: {
            requireAuth: true, //添加字段 表示进入这个路由是需要登录的
          },
          component: resolve => require(['@/views/line/LineList'], resolve),//懒加载,
        },
        {
          path: '/line/add', //添加线路
          name: 'line_add',
          meta: {
            requireAuth: true, //添加字段 表示进入这个路由是需要登录的
          },
          component: resolve => require(['@/views/line/children/AddLine'],resolve),//懒加载,
        },
        // 指南管理
        {
          path: '/guide/scenic',//景点评级
          name: 'guide_scenic',
          meta: {
            requireAuth: true, //添加字段 表示进入这个路由是需要登录的
          },
          component: resolve => require(['@/views/guide/ScenicGrade'], resolve),//懒加载,
        },
        {
          path: '/guide/stay',//住宿评级
          name: 'guide_stay',
          meta: {
            requireAuth: true, //添加字段 表示进入这个路由是需要登录的
          },
          component: resolve => require(['@/views/guide/StayGrade'], resolve),//懒加载,
        },
        {
          path: '/guide/flavor',//风味评级
          name: 'guide_flavor',
          meta: {
            requireAuth: true, //添加字段 表示进入这个路由是需要登录的
          },
          component: resolve => require(['@/views/guide/FlavorGrade'], resolve),//懒加载,
        },
        {
          path: '/guide/folkways',//民俗评级
          name: 'guide_folkways',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/guide/FolkwaysGrade'], resolve),//懒加载
        },
        {
          path: '/guide/standard',//评级标准
          name: 'guide_standard',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/guide/Standard'], resolve),//懒加载
        },

        // 消息管理
        {
          path: '/news/list',   //消息列表
          name: 'news_list',
          meta: {
            requireAuth: true,
          },
          component: resolve => require(['@/views/news/NewsList'], resolve),//懒加载
        },
        {
          path: '/news/publish',
          name: 'news_publish',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/news/children/PublishNews'], resolve), //懒加载
        },
        //用户管理
        {
          path: '/user/list',       //用户列表
          name: 'user_list',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/user/UserList'], resolve), //懒加载
        },
        {
          path: '/user/score',    //游客评分
          name: 'user_score',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/user/UserScore'], resolve), //懒加载
        },

        //旅说管理
        {
          path: '/say/list',    //旅说列表
          name: 'say_list',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/say/SayList'], resolve), //懒加载
        },

        //投诉管理
        {
          path: '/complaint/list',   //投诉列表
          name: 'complaint_list',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/complaint/ComplaintList'], resolve), //懒加载
        },
        {
          path: '/complaint/create',   //投诉导文
          name: 'complaint_create',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/complaint/children/Create'], resolve), //懒加载
        },

        //权限管理
        {
          path: '/power/role',   //角色授权
          name: 'power_role',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/power/Role'], resolve), //懒加载
        },
        {
          path: '/power/account',   //账号管理
          name: 'power_account',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/power/Account'], resolve), //懒加载
        },
        {
          path: '/advert/carousel',   //轮播广告管理
          name: 'advert_carousel',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/advert/AdvertCarousel'], resolve), //懒加载
        },
        {
          path: '/advert/article',   //文章广告管理
          name: 'advert_article',
          meta: {
            requireAuth: true
          },
          component: resolve => require(['@/views/advert/AdvertArticle'], resolve), //懒加载
        },

        //投稿
        {
          path: '/set/:id',   
          name: 'set',
          meta: {
            requireAuth: true
          },
          component: Set
        },
        
      ],
    },
    
    {
      path: '**',         //404
      name: '404',
      component: resolve => require(['@/views/404'], resolve)//懒加载
      
    }
    // {
    //   path: '/about',
    //   name: 'about',
    //   // route level code-splitting
    //   // this generates a separate chunk (about.[hash].js) for this route
    //   // which is lazy-loaded when the route is visited.
    //   component: () => import(/* webpackChunkName: "about" */ './views/About.vue')
    // },
    
  ],scrollBehavior(to, from, savedPosition) {
  return { x: 0, y: 0 };}
})

router.beforeEach((to, from, next)=> {
  if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
        if (localStorage.getItem('token')) {  
            next();
        }
        else {
            next({
                path: '/login',
            })
        }
    }
    else {
        next();
    }
}) 
export default router;